package game.data.implement;

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.Serializable;

import javax.imageio.ImageIO;

import game.data.interfaces.ImageData;

/**
 * gameImageData
 * =========================
 * Index 0 is empty Index reserved for grid or empty image
 * Index 1 to 99 is reserved for area images
 * Index 100 to 799 is reserved for movable/usable/block image
 * Index 800 to 899 is reserved for item images
 * Index 900 to 939 is reserved for player images
 * 
 * @author peters05
 *
 */

public class gameImageData implements ImageData, Serializable {
	
	private static final long serialVersionUID = 1L;
	BufferedImage[] imageList;
	
	public gameImageData() {
		imageList = new BufferedImage[939];
		imageList[0] = new BufferedImage(64, 64, BufferedImage.TYPE_INT_ARGB);
        try
        {
        	imageList[0] = ImageIO.read(new File("resource/textures/grid.png"));
        	imageList[1] = ImageIO.read(new File("resource/textures/dirt_full.png"));
        	imageList[2] = ImageIO.read(new File("resource/textures/grass_full.png"));
        	imageList[3] = ImageIO.read(new File("resource/textures/sand.png"));
        	imageList[4] = ImageIO.read(new File("resource/textures/stone_full.png"));
        	imageList[5] = ImageIO.read(new File("resource/textures/ice.png"));
        	imageList[6] = ImageIO.read(new File("resource/textures/lava.png"));
        	imageList[7] = ImageIO.read(new File("resource/textures/water.png"));
        	imageList[8] = ImageIO.read(new File("resource/textures/marble0.png"));
        	imageList[9] = ImageIO.read(new File("resource/textures/sand.png"));
        	imageList[10] = ImageIO.read(new File("resource/textures/swamp.png"));
        	imageList[11] = ImageIO.read(new File("resource/textures/marble1.png"));
        	
        	imageList[100] = ImageIO.read(new File("resource/textures/emptyblock.png"));
        	imageList[101] = ImageIO.read(new File("resource/textures/testblock.png"));
        	
        	imageList[900] = ImageIO.read(new File("resource/player/orc_idle_up.png"));
        	imageList[901] = ImageIO.read(new File("resource/player/orc_idle_right.png"));
        	imageList[902] = ImageIO.read(new File("resource/player/orc_idle_down.png"));
        	imageList[903] = ImageIO.read(new File("resource/player/orc_idle_left.png"));
        	
        	imageList[904] = ImageIO.read(new File("resource/player/orc_walkUpL.png"));
        	imageList[905] = ImageIO.read(new File("resource/player/orc_walkUpR.png"));
        	imageList[906] = ImageIO.read(new File("resource/player/orc_walkRightL.png"));
        	imageList[907] = ImageIO.read(new File("resource/player/orc_walkRightR.png"));
        	imageList[908] = ImageIO.read(new File("resource/player/orc_walkDownL.png"));
        	imageList[909] = ImageIO.read(new File("resource/player/orc_walkDownR.png"));
        	imageList[910] = ImageIO.read(new File("resource/player/orc_walkLeftL.png"));
        	imageList[911] = ImageIO.read(new File("resource/player/orc_walkLeftR.png"));
        	
        	imageList[912] = ImageIO.read(new File("resource/player/orc_action_up.png"));
        	imageList[913] = ImageIO.read(new File("resource/player/orc_action_right.png"));
        	imageList[914] = ImageIO.read(new File("resource/player/orc_action_down.png"));
        	imageList[915] = ImageIO.read(new File("resource/player/orc_action_left.png"));
        }
        catch(IOException e){System.out.println(e);}
		// loadImageData("default");
	}

	@Override
	public void loadImageData(String dataName) {
		gameImageData buffer = new gameImageData();
	      try
	      {
	    	  // Texturepack-Namen auflösen zum Laden
	         FileInputStream fileIn = new FileInputStream("resource/textures/"+dataName+".tpak");
	         ObjectInputStream in = new ObjectInputStream(fileIn);
	         buffer = (gameImageData) in.readObject();
	         in.close();
	         fileIn.close();
	      }catch(IOException i)
	      {
	         i.printStackTrace();
	         return;
	      }catch(ClassNotFoundException c)
	      {
	         c.printStackTrace();
	         return;
	      }
	      for(int i=0;i<20;i++)
			{
				for(int j=0;j<20;j++)
				{
					imageList = buffer.imageList.clone();
				}
			}
	      buffer = null;
	}

	@Override
	public BufferedImage[] getImageData() {
		return imageList;
	}

}
